package net.huashitong.synthetical.question.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.ObjectUtils;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.synthetical.question.entity.SupervisionLog;
import net.huashitong.synthetical.question.filter.TaskLogFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 催办记录dao
 */

@Repository
public class SupervisionLogDao extends StringDao<SupervisionLog> {


    /**
     * 获取催办记录
     * @param filter
     * @return
     */
    public List<SupervisionLog> getMissionLog(String id )
    {
        GenericQuery query = createQuery( "t");
        query.append(" and  t.taskId=:taskId").setParam("taskId",id);
        return query.listResult();
    }

    public List<SupervisionLog> querySupervisionLogs(TaskLogFilter filter){
        GenericQuery query = createQuery("obj");
        if (ObjectUtils.isNotBlank(filter.getSysId())) {
            query.append(" and obj.sysId=:sysId").setParam("sysId", filter.getSysId());
        }
        if(StringUtils.isNotBlank(filter.getTaskName())){
            query.append(" and obj.taskName like :taskName");
            query.setParam("taskName", StringUtils.getLikewords(filter.getTaskName()));
        }
        if (ObjectUtils.isNotBlank(filter.getSupervisionTeamId())) {
            query.append(" and obj.supervisionTeamId=:supervisionTeamId").setParam("supervisionTeamId", filter.getSupervisionTeamId());
        }
        if (ObjectUtils.isNotBlank(filter.getTaskId())) {
            query.append(" and obj.taskId=:taskId").setParam("taskId", filter.getTaskId());
        }
        return query.listResult(filter);
    }
}
